import React, { useEffect, useState } from 'react'
import { useDispatch } from 'umi'
import { getExamSubject, getExamType1, getExamType ,allexam} from '@/services/index'
import { Radio, Select } from 'antd';

const QuestionType: React.FC = () => {
  const { Option } = Select;
  const [getClass, setClass] = useState<any[]>([])
  const [getSub, setSub] = useState<any[]>([])
  const [getExam, setExam] = useState<any[]>([])
  const [getaaa, setall] = useState<any[]>([])

  // 通过useDispatch拿到派发redux的dispatch
  const dispatch = useDispatch();

  function handleChange(value: any) {
    // console.log(`selected ${value}`);
  }



  useEffect(() => {
    dispatch({
      type: 'question/getQuestionType'
    })
  }, []);

  useEffect(() => {
    getExamSubject().then(res => {
      setClass(res.data);
    })
  }, [])

  useEffect(() => {
    getExamType1().then(res => {
      setSub(res.data);
    })
  },[])


  useEffect(() => {
    allexam().then(res => {
      setall(res.data);
      console.log(res.data,'--------')
    })
  },[])


  useEffect(() => {
    getExamType().then(res => {
      setExam(res.data);
    })
  },[])
  
  function onChange(e: any) {
    // console.log(`radio checked:${e.target.value}`);
  }
  return (
    <div>
      {/* <h1>查看试卷</h1> */}
      <dl>
        <dt>
          课程类型:
      </dt>
        <dd>
          <>
            <Radio.Group onChange={onChange} defaultValue="a">
              {
                getClass.map((item, index) => {
                  return <Radio.Button value={index} key={index}>{item.subject_text}</Radio.Button>
                })
              }
            </Radio.Group>
          </>
        </dd>
      </dl>
      <dl>
        <dt>考试类型:</dt>
        <dd>
          <>
            <Select defaultValue="" style={{ width: 120 }} onChange={handleChange}>
              {
                getSub.map((item, index) => {
                  return <Option value={item.exam_name} key={index}>{item.exam_name}</Option>
                })
              }
            </Select>
          </>
        </dd>
        <dt>题目类型:</dt>
        <dd>
          <>
            <Select defaultValue="" style={{ width: 120 }} onChange={handleChange}>
              {
                getExam.map((item, index) => {
                  return <Option value={item.questions_type_text} key={index}>{item.questions_type_text}</Option>
                })
              }
            </Select>
          </>
        </dd>
      </dl>
      {
        getaaa.map((item,index)=>{
          return <div key={index} className='aaa'>
            <p key={index}>{item.title}</p>
            <span>{item.questions_type_text}</span>
            <span>{item.subject_text}</span>
            <span>{item.exam_name}</span>
          </div>
        })
      }
    </div>

  );
}

export default QuestionType;
